package loaderData
{
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	/**
	 * XML加载 
	 * @author weiping
	 * 
	 */	
	public class LoaderXml extends BaseLoader
	{
		private var m_Loader:URLLoader;
		public function LoaderXml()
		{
			m_Loader = new URLLoader();
		}
		
		override public function load(url:String):void
		{
			this.loaderUrl = url;
			m_Loader.addEventListener(Event.COMPLETE, onCompleteEvent);
			m_Loader.addEventListener(IOErrorEvent.IO_ERROR, onIoErrorEvent);
			m_Loader.addEventListener(ProgressEvent.PROGRESS, onProgressEvent);
			m_Loader.addEventListener(Event.OPEN, onOpen);
			
			m_Loader.load(new URLRequest(url));
		}
		
		override protected function onCompleteEvent(event:Event):void
		{
			this.objData = XML(event.target.data);
			super.onCompleteEvent(event);
		}
		
		override protected function onIoErrorEvent(event:IOErrorEvent):void
		{
			super.onIoErrorEvent(event);
		}
		
		override protected function onProgressEvent(event:ProgressEvent):void
		{
			this.bytesLoadNum = event.bytesLoaded;
			this.bytesTotalNum = event.bytesTotal;
			super.onProgressEvent(event);
		}
		
		override protected function onOpen(event:Event):void
		{
			super.onOpen(event);
		}
		
		override public function clear():void
		{
			super.clear();
			m_Loader.close();
			removeEvent();
		}
		
		protected function removeEvent():void
		{
			m_Loader.removeEventListener(Event.COMPLETE, onCompleteEvent);
			m_Loader.removeEventListener(IOErrorEvent.IO_ERROR, onIoErrorEvent);
			m_Loader.removeEventListener(ProgressEvent.PROGRESS, onProgressEvent);
			m_Loader.removeEventListener(Event.OPEN, onOpen);
		}

	}
}